package com.grandbroad.eim.ui.activities;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.widget.ImageView;
import android.widget.TextView;

import com.easy.west.westclient.api.login.bean.User;
import com.easy.west.westclient.api.user.bean.FollowList;
import com.easy.west.westclient.api.user.bean.UserList;
import com.easy.west.westclient.api.user.event.GetFollowListEvent;
import com.easy.west.westclient.api.vodcommen.bean.CommenList;
import com.grandbroad.eim.R;
import com.grandbroad.eim.adapter.FollowedListAdapter;
import com.grandbroad.eim.app.MyApplication;
import com.grandbroad.eim.base.BaseActivity;
import com.grandbroad.eim.utils.CacheUtils;
import com.grandbroad.eim.utils.UiUtlis;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 关注列表
 */
public class FollowListActivity extends BaseActivity {


    @BindView(R.id.img_back_btn)
    ImageView imgBackBtn;
    @BindView(R.id.tv_toolbar_title)
    TextView tvToolbarTitle;
    @BindView(R.id.tool_bar)
    Toolbar toolBar;
    @BindView(R.id.recycler_commenlist)
    RecyclerView recyclerCommenlist;
    @BindView(R.id.swipe_layout)
    SwipeRefreshLayout swipeLayout;
    private int defult_count = 25;
    private User user;
    private FollowedListAdapter listAdapter;
    @Override
    protected void initview() {
        swipeLayout.setColorSchemeColors(UiUtlis.getColor(R.color.TextFont));
        swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                defult_count = 25;
               MyApplication.getMoleclient().getMyfollowList(defult_count,user.getAccess_token());
            }
        });
        if (user.getAccess_token().equals(CacheUtils.getUser().getAccess_token()))
        {
            tvToolbarTitle.setText("我的关注");

        }
        else
        {
            tvToolbarTitle.setText(user.getName()+"的关注");
        }
        toolBar.setBackgroundColor(Color.WHITE);
        listAdapter = new FollowedListAdapter();
        recyclerCommenlist.setAdapter(listAdapter);
        recyclerCommenlist.setLayoutManager(new LinearLayoutManager(this));
        recyclerCommenlist.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                switch (newState)
                {
                    case RecyclerView.SCROLL_STATE_IDLE:
                        //到底了
                        defult_count=defult_count+20;
                        MyApplication.getMoleclient().getMyfollowList(defult_count,user.getAccess_token());
                        break;

                }
            }
        });
        setBackBtn(imgBackBtn);

    }

    @Override
    protected void initdata() {
        user = (User) getIntent().getExtras().getSerializable("bean");
        //根据传入的accestoken做出变化
        MyApplication.getMoleclient().getMyfollowList(defult_count,user.getAccess_token());
    }


    @Override
    protected int setlayout() {
        return R.layout.activity_follow_list;
    }

    /**
     * 获取关注的列表
     * @param eva
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getFollowedList(GetFollowListEvent eva)
    {
        if (eva.isOk())
        {
            FollowList list = eva.getBean();
                listAdapter.setUserList(list.getLiverooms());
                listAdapter.notifyDataSetChanged();
                swipeLayout.setRefreshing(false);
        }
    }
}
